package tsinghua.smxq.utilitiespayment;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import tsinghua.smxq.mc.Constants;
import tsinghua.smxq.mc.ICBCLogonActivity;
import tsinghua.smxq.mc.R;
import tsinghua.smxq.mc.Session;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.Button;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.SimpleAdapter;
import android.widget.Toast;

/*
 * 本段代码，参考自csdn中的一篇文章，网址为：http://blog.csdn.net/kkfdsa132/article/details/6416114
 */

public class RecordsTable extends LinearLayout implements OnClickListener,
		OnItemClickListener, OnItemLongClickListener {
	private Context context; // 上下文
	private GridView gv_titles; // 字段视图
	private GridView gv_body; // 数据视图
	private LinearLayout bottomLayout; // 视图底部布局
	private Button bt_next, bt_pre, bt_first, bt_last, bt_refresh; // 按钮：下一页、上一页、首页、尾页

	private String[][] items; // [字段][显示的名称]
	private SimpleAdapter titlesAdatper; // 字段视图适配器
	private int TableRowCount; // 每页显示条数
	private int pageID; // 当前页码
	private int TotalCount; // 总记录条数
	private int pageCount; // 总页数
	private String[] fields; // 字段名称
	private boolean[] isDesc; // 排序方式标记：false-递增排序，true-递减排序
	private ArrayList<HashMap<String, String>> dataList = new ArrayList<HashMap<String, String>>(); // 数据集合
	private List<Record> records = new ArrayList<Record>();
	private JSONArray jsonarray;
	private JSONObject jsonobject;
	private Record record;
	Record selectedRecord;
	public String city;
	int cityID = -1;
	public String cardId;
	int month;
	public String unitprice;
	boolean isAll;
	int type;
	URL url;
	Toast toast;
	String result = "";
	private int status;

	public RecordsTable(Context context) {
		super(context);
		this.context = context;
	}

	/**
	 * 表格视图
	 * 
	 * @param context
	 *            上下文
	 * @param items
	 *            字段名和对应显示名称 *
	 * @param displayNum
	 *            每页的最大记录数
	 */
	public RecordsTable(Context context, String[][] items, int TableRowCount,
			int t, boolean ia, int mo) {
		super(context);
		this.type = t;
		this.context = context;
		this.items = items;
		this.TableRowCount = TableRowCount;
		this.isAll = ia;
		if (!ia) {
			month = mo;
			DisplayToast(month + "月", Toast.LENGTH_SHORT);
		}
		// 连接服务器更新histories
		updateRecords();

		// 排序方式标记：false-递增排序，true-递减排序
		isDesc = new boolean[items.length];
		// 当前页码
		pageID = 0;
		// 记录总数
		TotalCount = this.records.size();
		// 总页码
		pageCount = TotalCount % TableRowCount == 0 ? TotalCount
				/ TableRowCount - 1 : TotalCount / TableRowCount;
		// 字段名称
		fields = new String[items.length];
		for (int i = 0; i < items.length; i++) {
			fields[i] = items[i][0];
		}

		setField(); // 字段视图
		setBody(); // 数据视图
		setBottomLayout(); // 底部视图
		setOrientation(LinearLayout.VERTICAL);
		addView(gv_titles); // 添加视图
		addView(gv_body);
		addView(bottomLayout);

	}

	public void refresh() {
		// 连接服务器更新histories
		updateRecords();
		removeView(gv_body);
		removeView(bottomLayout);
		// 排序方式标记：false-递增排序，true-递减排序
		isDesc = new boolean[items.length];
		// 当前页码
		pageID = 0;
		// 记录总数
		TotalCount = this.records.size();
		// 总页码
		pageCount = TotalCount % TableRowCount == 0 ? TotalCount
				/ TableRowCount - 1 : TotalCount / TableRowCount;
		// 字段名称
		fields = new String[items.length];
		for (int i = 0; i < items.length; i++) {
			fields[i] = items[i][0];
		}

		setField(); // 字段视图
		setBody(); // 数据视图
		setBottomLayout(); // 底部视图
		setOrientation(LinearLayout.VERTICAL);
		addView(gv_body);
		addView(bottomLayout);
	}

	// 返回所有的水费记录
	public void getAllWaterRecordByUserId(int ui) throws URISyntaxException,
			ClientProtocolException, IOException, JSONException {
		// 连接服务器
		HttpClient httpclient = new DefaultHttpClient();
		ArrayList<NameValuePair> qparams = new ArrayList<NameValuePair>();
		qparams.add(new BasicNameValuePair("method",
				"getAllWaterRecordByUserId"));
		qparams.add(new BasicNameValuePair("userid", String
				.valueOf(Session.user.getId())));
		URI uri = URIUtils.createURI("http", Constants.serverIP, 8080,
				"MobileCityServer/InquiryLogServlet",
				URLEncodedUtils.format(qparams, "UTF-8"), null);
		HttpGet httpget = new HttpGet(uri);
		HttpResponse response = httpclient.execute(httpget);
		HttpEntity entity = response.getEntity();
		if (entity != null) {
			String contentString = EntityUtils.toString(entity);
			JSONObject o = new JSONObject(contentString);
			status = o.getInt("status");
			if (status == 0) {
				DisplayToast("无水费记录", Toast.LENGTH_SHORT);
			} else {
				jsonarray = o.getJSONArray("waterRecord");
				for (int i = 0, length = jsonarray.length(); i < length; i++) {
					jsonobject = jsonarray.getJSONObject(i);					
					record = new Record(jsonobject.getString("id"),
							jsonobject.getString("cityId"),
							Integer.valueOf(jsonobject.getString("month")),
							Float.valueOf(jsonobject.getString("usage")),
							Float.valueOf(jsonobject.getString("unitPrice")),
							Float.valueOf(jsonobject.getString("rate")),
							jsonobject.getString("hasPaid"));
					records.add(record);

				}
			}
		}

	}

	// 返回所有的电费记录
	public void getAllElectricityRecordByUserId(int ui)
			throws URISyntaxException, ClientProtocolException, IOException,
			JSONException {
		// 连接服务器
		// 连接服务器
		HttpClient httpclient = new DefaultHttpClient();
		ArrayList<NameValuePair> qparams = new ArrayList<NameValuePair>();
		qparams.add(new BasicNameValuePair("method",
				"getAllElectricityRecordByUserId"));
		qparams.add(new BasicNameValuePair("userid", String
				.valueOf(Session.user.getId())));
		URI uri = URIUtils.createURI("http", Constants.serverIP, 8080,
				"MobileCityServer/InquiryLogServlet",
				URLEncodedUtils.format(qparams, "UTF-8"), null);
		HttpGet httpget = new HttpGet(uri);
		HttpResponse response = httpclient.execute(httpget);
		HttpEntity entity = response.getEntity();
		if (entity != null) {
			String contentString = EntityUtils.toString(entity);
			JSONObject o = new JSONObject(contentString);
			status = o.getInt("status");
			if (status == 0) {
				DisplayToast("无电费记录", Toast.LENGTH_SHORT);
			} else {

				jsonarray = o.getJSONArray("electricityRecord");
				for (int i = 0, length = jsonarray.length(); i < length; i++) {
					jsonobject = jsonarray.getJSONObject(i);
					record = new Record(jsonobject.getString("id"),
							jsonobject.getString("cityId"),
							Integer.valueOf(jsonobject.getString("month")),
							Float.valueOf(jsonobject.getString("usage")),
							Float.valueOf(jsonobject.getString("unitPrice")),
							Float.valueOf(jsonobject.getString("rate")),
							jsonobject.getString("hasPaid"));
					records.add(record);
				}
			}
		}

	}

	// 返回某个月的水费记录
	public void getWaterRecordByUserId(int ui, int mo)
			throws URISyntaxException, ClientProtocolException, IOException,
			JSONException {
		// 连接服务器
		HttpClient httpclient = new DefaultHttpClient();
		ArrayList<NameValuePair> qparams = new ArrayList<NameValuePair>();
		qparams.add(new BasicNameValuePair("method",
				"getOneWaterRecordByUserId"));
		qparams.add(new BasicNameValuePair("userid", String
				.valueOf(Session.user.getId())));
		qparams.add(new BasicNameValuePair("month", String.valueOf(this.month)));
		URI uri = URIUtils.createURI("http", Constants.serverIP, 8080,
				"MobileCityServer/InquiryLogServlet",
				URLEncodedUtils.format(qparams, "UTF-8"), null);
		HttpGet httpget = new HttpGet(uri);
		HttpResponse response = httpclient.execute(httpget);
		HttpEntity entity = response.getEntity();
		if (entity != null) {
			String contentString = EntityUtils.toString(entity);
			JSONObject o = new JSONObject(contentString);
			status = o.getInt("status");
			if (status == 0) {
				DisplayToast("无水费记录", Toast.LENGTH_SHORT);
			} else {
				jsonarray = o.getJSONArray("waterRecord");
				for (int i = 0, length = jsonarray.length(); i < length; i++) {
					jsonobject = jsonarray.getJSONObject(i);
					record = new Record(jsonobject.getString("id"),
							jsonobject.getString("cityId"),
							Integer.valueOf(jsonobject.getString("month")),
							Float.valueOf(jsonobject.getString("usage")),
							Float.valueOf(jsonobject.getString("unitPrice")),
							Float.valueOf(jsonobject.getString("rate")),
							jsonobject.getString("hasPaid"));
					records.add(record);
				}
			}

		}
	}

	// 返回某个月的电费记录
	public void getElectricityRecordByUserId(int ui, int mo)
			throws ClientProtocolException, IOException, URISyntaxException,
			JSONException {
		HttpClient httpclient = new DefaultHttpClient();
		ArrayList<NameValuePair> qparams = new ArrayList<NameValuePair>();
		qparams.add(new BasicNameValuePair("method",
				"getOneElectricityRecordByUserId"));
		qparams.add(new BasicNameValuePair("userid", String
				.valueOf(Session.user.getId())));
		qparams.add(new BasicNameValuePair("month", String.valueOf(this.month)));
		URI uri = URIUtils.createURI("http", Constants.serverIP, 8080,
				"MobileCityServer/InquiryLogServlet",
				URLEncodedUtils.format(qparams, "UTF-8"), null);
		HttpGet httpget = new HttpGet(uri);
		HttpResponse response = httpclient.execute(httpget);
		HttpEntity entity = response.getEntity();
		if (entity != null) {
			String contentString = EntityUtils.toString(entity);
			JSONObject o = new JSONObject(contentString);
			status = o.getInt("status");
			if (status == 0) {
				DisplayToast("无电费记录", Toast.LENGTH_SHORT);
			} else {
				jsonarray = o.getJSONArray("electricityRecord");
				for (int i = 0, length = jsonarray.length(); i < length; i++) {
					jsonobject = jsonarray.getJSONObject(i);
					record = new Record(jsonobject.getString("id"),
							jsonobject.getString("cityId"),
							Integer.valueOf(jsonobject.getString("month")),
							Float.valueOf(jsonobject.getString("usage")),
							Float.valueOf(jsonobject.getString("unitPrice")),
							Float.valueOf(jsonobject.getString("rate")),
							jsonobject.getString("hasPaid"));
					records.add(record);
				}
			}
		}

	}

	public void updateRecords() {
		try {
			records.clear();
			// 所有记录
			if (isAll) {
				if (this.type == 0) {
					this.getAllWaterRecordByUserId(Session.user.getId());

				} else {
					this.getAllElectricityRecordByUserId(Session.user.getId());
				}
			} else {
				if (this.type == 0) {
					this.getWaterRecordByUserId(Session.user.getId(), month);
				} else {
					this.getElectricityRecordByUserId(Session.user.getId(),
							month);
				}
			}
			DisplayToast("数据刷新完成",Toast.LENGTH_SHORT);
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (URISyntaxException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * 设置字段视图
	 */
	private void setField() {
		gv_titles = new GridView(context);
		gv_titles.setNumColumns(items.length);

		// 字段标题
		ArrayList<HashMap<String, String>> titles = new ArrayList<HashMap<String, String>>();
		for (int i = 0; i < items.length; i++) {
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("title", items[i][1]);
			titles.add(map);
		}
		titlesAdatper = new SimpleAdapter(context, titles,
				R.layout.items_utilities, new String[] { "title" },
				new int[] { R.id.ItemText_utilities });
		gv_titles.setAdapter(titlesAdatper);

		// 点击字段标题，改变排序方式
		gv_titles.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				switch (arg2) {
				case 0:
					if (isDesc[arg2]) {
						OrderedByrecordId(true);
						isDesc[arg2] = false;
					} else {
						OrderedByrecordId(false);
						isDesc[arg2] = true;
					}
					break;
				case 1:
					if (isDesc[arg2]) {
						OrderedByMonth(true);
						isDesc[arg2] = false;
					} else {
						OrderedByMonth(false);
						isDesc[arg2] = true;
					}
					break;
				case 2:
					if (isDesc[arg2]) {
						OrderedByUsage(true);
						isDesc[arg2] = false;
					} else {
						OrderedByUsage(false);
						isDesc[arg2] = true;
					}
					break;
				case 3:
					if (isDesc[arg2]) {
						OrderedByStatus(true);
						isDesc[arg2] = false;
					} else {
						OrderedByStatus(false);
						isDesc[arg2] = true;
					}
					break;
				default:
					break;
				}
				toPage(0);
			}
		});
	}

	/*
	 * 按照priceDate进行排序
	 */
	public void OrderedByStatus(boolean assend) {
		Record p, q;
		int count = this.records.size();
		int i, j;
		// 先按照升序排列
		for (i = 0; i < count - 1; i++) {
			for (j = count - 1; j > i; j--) {
				p = this.records.get(j);
				q = this.records.get(j - 1);
				if ((p.hasPaid == "否") && q.hasPaid == "是") {
					this.records.set(j, q);
					this.records.set(j - 1, p);
				}
			}
		}

		// 降序
		if (!assend) {
			Collections.reverse(this.records);
		}
	}

	/*
	 * 按照市场名字进行排序
	 */
	public void OrderedByrecordId(boolean assend) {
		Record p, q;
		int count = this.records.size();
		int i, j;
		// 先按照升序排列
		for (i = 0; i < count - 1; i++) {
			for (j = count - 1; j > i; j--) {
				p = this.records.get(j);
				q = this.records.get(j - 1);
				if (p.recordId.compareToIgnoreCase(q.recordId) < 0) {
					this.records.set(j, q);
					this.records.set(j - 1, p);
				}
			}
		}

		// 降序
		if (!assend) {
			Collections.reverse(this.records);
		}
	}

	/*
	 * 按照菜的种类进行排序
	 */
	public void OrderedByMonth(boolean assend) {
		Record p, q;
		int count = this.records.size();
		int i, j;
		// 先按照升序排列
		for (i = 0; i < count - 1; i++) {
			for (j = count - 1; j > i; j--) {
				p = this.records.get(j);
				q = this.records.get(j - 1);
				if (p.month < q.month) {
					this.records.set(j, q);
					this.records.set(j - 1, p);
				}
			}
		}

		// 降序
		if (!assend) {
			Collections.reverse(this.records);
		}
	}

	/*
	 * 按照菜价进行排序
	 */
	public void OrderedByUsage(boolean assend) {
		Record p, q;
		int count = this.records.size();
		int i, j;
		// 先按照升序排列
		for (i = 0; i < count - 1; i++) {
			for (j = count - 1; j > i; j--) {
				p = this.records.get(j);
				q = this.records.get(j - 1);
				if (p.usage < q.usage) {
					this.records.set(j, q);
					this.records.set(j - 1, p);
				}
			}
		}

		// 降序
		if (!assend) {
			Collections.reverse(this.records);
		}
	}

	/**
	 * 设置表格数据视图
	 */
	private void setBody() {
		gv_body = new GridView(context);
		gv_body.setNumColumns(items.length);

		toPage(0); // 转到第一页
		gv_body.setOnItemLongClickListener(this);
		gv_body.setOnItemClickListener(this); // 点击数据事件

	}

	/**
	 * 设置底部翻页视图， 由如下组成：首页、上一页、下一页、尾页、页码选择、当期页码提示
	 */
	private void setBottomLayout() {
		// 底部容器
		bottomLayout = new LinearLayout(context);
		bottomLayout.setOrientation(LinearLayout.HORIZONTAL);
		bottomLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.WRAP_CONTENT));
		// 翻页按钮
		bt_pre = new Button(context); // 上一页
		bt_next = new Button(context); // 下一页
		bt_first = new Button(context); // 首页
		bt_last = new Button(context); // 尾页
		bt_refresh = new Button(context);// 刷新
		// 设置文本
		bt_pre.setText("上一页");
		bt_next.setText("下一页");
		bt_first.setText("首  页");
		bt_last.setText("尾  页");
		bt_refresh.setText("刷  新");

		// 设置事件

		bt_first.setOnClickListener(this);
		bt_pre.setOnClickListener(this);
		bt_last.setOnClickListener(this);
		bt_next.setOnClickListener(this);
		bt_refresh.setOnClickListener(new Button.OnClickListener() {

			@Override
			public void onClick(View v) {
				bt_refresh.setClickable(false);
				DisplayToast("正在刷新数据...",Toast.LENGTH_SHORT);
				refresh();
				bt_refresh.setClickable(true);
			}

		});
		// 设置文本大小
		bt_first.setTextSize(10);
		bt_pre.setTextSize(10);
		bt_last.setTextSize(10);
		bt_next.setTextSize(10);
		bt_refresh.setTextSize(10);

		// 添加到底部容器
		bottomLayout.addView(bt_first);
		bottomLayout.addView(bt_pre);
		bottomLayout.addView(bt_next);
		bottomLayout.addView(bt_last);
		bottomLayout.addView(bt_refresh);
	}

	// 设置显示大小
	public void setSize(View v) {
		v.setLayoutParams(new android.view.ViewGroup.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
	}

	/**
	 * 翻页点击事件
	 */
	@Override
	public void onClick(View v) {

		if(v == bt_first) {	//第一页
			if(pageID == 0)
			{
				DisplayToast("已经到达首页",Toast.LENGTH_SHORT);
				return;
			}
			else
			{
				pageID = 0;
				toPage(pageID);
			}				
		}else if(v == bt_last) {	//最后一页
			if(pageCount == 0) {
				DisplayToast("已经到达尾页",Toast.LENGTH_SHORT);
				return;
			}
			pageID = pageCount;
			toPage(pageID);
		}else if(v == bt_next) {	//下一页
			if(pageID < pageCount) {
				++pageID;
				toPage(pageID);
			} else {
				DisplayToast("已经到达尾页",Toast.LENGTH_SHORT);
				return;
			}
			
		}else if(v == bt_pre) {	//上一页
			if(pageID <= 0){
				DisplayToast("已经到达首页",Toast.LENGTH_SHORT);
				return;
			}else {
				--pageID;
				toPage(pageID);
			}
		}		
		
	}

	/**
	 * 跳转页面
	 * 
	 * @param startIndex
	 *            开始页码
	 * @param sql
	 *            查询语句
	 */
	public void toPage(int startIndex) {
		// 获取查询结果集合
		ArrayList<HashMap<String, String>> temp = query2(context, fields);
		int index = startIndex * this.TableRowCount * this.items.length;
		int endIndex = Math.min(temp.size() - 1,
				(index + this.items.length - 1 + (this.TableRowCount - 1)
						* this.items.length));
		// 清空原来的数据
		dataList.clear();
		// 添加新的数据
		for (int i = index; i <= endIndex; i++) {
			dataList.add(temp.get(i));
		}
		// 设置适配器
		SimpleAdapter simpleAdapter = new SimpleAdapter(context, dataList,
				R.layout.items_utilities, new String[] { "item" },
				new int[] { R.id.ItemText_utilities });
		gv_body.setAdapter(simpleAdapter); // 重新添加适配器
	}

	public ArrayList<HashMap<String, String>> query2(Context context,
			String[] fields) {

		ArrayList<HashMap<String, String>> dataList = new ArrayList<HashMap<String, String>>();
		Record temp;
		HashMap<String, String> map;
		Iterator<Record> it = records.iterator();
		while (it.hasNext()) {
			temp = it.next();
			map = new HashMap<String, String>();
			map.put("item", String.valueOf(temp.recordId));
			dataList.add(map);
			map = new HashMap<String, String>();
			map.put("item", String.valueOf(temp.month));
			dataList.add(map);
			map = new HashMap<String, String>();
			map.put("item", String.valueOf(temp.usage));
			dataList.add(map);

			map = new HashMap<String, String>();
			if (temp.hasPaid.compareToIgnoreCase("1") == 0) {
				map.put("item", "已支付");
			} else {
				map.put("item", "未支付");
			}
			dataList.add(map);
		}
		return dataList;
	}

	/**
	 * 数据项点击事件
	 */
	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		AlertDialog showChangeDialog;
		int index = TableRowCount * pageID + arg2 / items.length;
		selectedRecord = findRecord(index);
		if (selectedRecord != null) {
			showInfoDialog(selectedRecord);
			// 更新records
			refresh();
		}
	}

	@Override
	public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2,
			long arg3) {
		Toast.makeText(context,
				((HashMap<String, String>) dataList.get(arg2)).get("item"),
				Toast.LENGTH_SHORT).show();
		return true;
	}

	public Record findRecord(int index) {
		if (index < 0 || index >= records.size()) {
			return null;
		} else {
			return records.get(index);
		}
	}

	// 查看详细信息
	protected void showInfoDialog(final Record record) {
		AlertDialog.Builder adb = new AlertDialog.Builder(this.context)
				/** 设置标题 **/
				.setTitle("详细信息")
				/** 设置icon **/
				.setIcon(R.drawable.about)
				/** 设置内容 **/
				.setMessage(
						"类型：\t"
								+ (type == 0 ? "水费" : "电费")
								+ "\n记录编号：\t"
								+ record.recordId
								+ "\n用户编号：\t"
								+ Session.user.getId()
								+ "\n城市编号：\t"
								+ record.cityId
								+ "\n月份：\t"
								+ record.month
								+ "\n数量：\t"
								+ record.usage
								+ "\n单价：\t"
								+ record.unitprice
								+ "\n总额：\t"
								+ record.rate
								+ "\n支付状态:"
								+ (record.hasPaid.compareToIgnoreCase("1") == 0 ? "已支付"
										: "未支付"));
		adb.setNegativeButton("关闭", new DialogInterface.OnClickListener() {

			public void onClick(DialogInterface dialog, int which) {
				dialog.cancel();
			}
		});
		if (record.hasPaid.compareToIgnoreCase("0") == 0) {
			adb.setPositiveButton("付款", new DialogInterface.OnClickListener() {

				public void onClick(DialogInterface dialog, int which) {
					// 传递参数
					Intent gotoIntent = new Intent(context,
							ICBCLogonActivity.class);
					gotoIntent.putExtra("type", type);
					gotoIntent.putExtra("recordId", record.recordId);
					gotoIntent.putExtra("cityId", record.cityId);
					gotoIntent.putExtra("month", record.month);
					gotoIntent.putExtra("usage", record.usage);
					gotoIntent.putExtra("unitprice", record.unitprice);
					gotoIntent.putExtra("rate", record.rate);
					context.startActivity(gotoIntent);
				}
			});

		}
		adb.show();
	}

	// 显示信息
	public void DisplayToast(String str, int time) {
		toast = Toast.makeText(this.context, str, time);
		// 设置toast显示的位置
		toast.setGravity(Gravity.TOP, 0, 320);
		// 显示该Toast
		toast.show();
	}

}